<?php
/**
 * Hesperos libraries
 *
 * @author       Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright    Copyright (c) 2011 Krzysztof Kardasz
 * @category     Hesperos
 * @package      Model
 * @subpackage   Domain
 * @version 	 SVN: $Id$
 * @filesource
 */

/**
 * Data Mapper (TableDataGateway)
 *
 * @author       Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright    Copyright (c) 2011 Krzysztof Kardasz
 * @category     Hesperos
 * @package      Model
 * @subpackage   Domain
 */
abstract class Hesperos_Model_Mapper_TableDataGateway extends Hesperos_Model_Mapper
{
    /**
     * Definiuje źródło danych (table data gateway)
     *
     * @param Hesperos_Model_Gateway_Table $table
     * @return void
     */
    public function setTable (Hesperos_Model_Gateway_Table $table)
    {
        $this->setDataSource($table);
    }

    /**
     * Zwraca źródło danych (table data gateway)
     *
     * @return Hesperos_Model_Gateway_Table
     * @throws Exception
     */
    public function getTable ()
    {
        $table = $this->getDataSource();
        if($table === null ) {
            throw new Exception ('Table data gateway is not set');
        } else if(!$table instanceof Hesperos_Model_Gateway_Table) {
            throw new Exception ('Mapper has another source: ' . get_class($table));
        }
        return $table;
    }
}